package com.example.task1.ui.AllService.bus;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.BusPathBean;
import com.example.task1.bean.BusPathDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.ui.BaseAdapter;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

public class BusAdapter extends BaseAdapter<BusPathBean.RowsDTO> {

    private Context context;
    private List<BusPathBean.RowsDTO> mData = new ArrayList<>();
    private TextView tvName;
    private TextView tvMileage;
    private TextView tvFirst;
    private TextView tvEnd;
    private RecyclerView rvList;
    private TextView tvTartTime;
    private TextView tvEndTime;
    private ArrayList<BusPathDetailsBean> mList = new ArrayList<>();

    public BusAdapter(Context context) {
        this.context = context;
    }

    @Override
    public void setData(List<BusPathBean.RowsDTO> rows) {
        mData = rows;
        notifyDataSetChanged();
    }

    @Override
    protected int getLayout() {
        return R.layout.buslist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<BusPathBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, BusPathBean.RowsDTO date) {

    }

    @Override
    protected void onBind(myHolder holder, BusPathBean.RowsDTO date, int position) {
        tvName.setText(date.getName());
        tvEnd.setText(date.getEnd());
        tvFirst.setText(date.getFirst());
        tvEndTime.setText("末班时间：" + date.getEndTime());
        tvTartTime.setText("首班时间：" + date.getStartTime());
        tvMileage.setText(date.getMileage() + "公里");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context,BusDetailsActivity.class,date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private void initView(View view) {
        tvName = (TextView) view.findViewById(R.id.tv_name);
        tvMileage = (TextView) view.findViewById(R.id.tv_mileage);
        tvFirst = (TextView) view.findViewById(R.id.tv_first);
        tvEnd = (TextView) view.findViewById(R.id.tv_end);
        tvTartTime = (TextView) view.findViewById(R.id.tv_tartTime);
        tvEndTime = (TextView) view.findViewById(R.id.tv_endTime);
    }
}
